/////////////////////////////////////////////////////////////////////////////
// Copyright(c) 2012-2015 purang All Rights Reserved
// Name:        socket_proxy_common.h
// Purpose:
// Author:      syy
// Modified by:
// Created:     2014/8/28 17:25
// RCS-ID:
// Licence:
/////////////////////////////////////////////////////////////////////////////
#ifndef _SOCKET_PROXY_COMMON_H_
#define _SOCKET_PROXY_COMMON_H_
#include <string>

#include "core/common_types.h"
enum ProxyType {
  kProxyNone,
  kProxyBrowser,
  kProxyHttp,
  kProxySocksVer4 = 4,
  kProxySocksVer5,
};

#pragma pack(1)
struct socks5req1 {
  char Ver;
  char nMethods;
  char Methods[2];
};

struct socks5ans1 {
  char Ver;
  char Method;
};

struct socks5req2 {
  char Ver;
  char Cmd;
  char Rsv;
  char Atyp;
  uint32_t IPAddr;
  uint16_t Port;
};

struct socks5ans2 {
  char Ver;
  char Rep;
  char Rsv;
  char Atyp;
  char other[1];
};

struct authreq {
  char Ver;
  char Ulen;
  char NamePass[513];
};

struct authans {
  char Ver;
  char Status;
};

struct udpassociatereq {
  char Ver;
  char Cmd;
  char Rsv;
  char Atyp;
  uint32_t IPAddr;
  uint16_t Port;
};

struct udpassociateans {
  char Ver;
  char Rep;
  char Rsv;
  char Atyp;
  uint32_t IPAddr;
  uint16_t Port;
};

struct udpheader {
  uint16_t Rsv;
  char Frag;
  char Atyp;
  uint32_t IPAddr;
  uint16_t Port;
};
#pragma pack()

struct ProxyInfo {
  ProxyInfo() {
    nProxyType = kProxyNone;
    bUse = false;
    nProxyPort = 0;
  }
  ProxyInfo& operator=(const ProxyInfo& info) {
    strProxyHost = info.strProxyHost;
    strUsername = info.strUsername;
    strPassword = info.strPassword;
    strDomain = info.strDomain;
    nProxyPort = info.nProxyPort;
    nProxyType = info.nProxyType;
    bUse = info.bUse;

    return *this;
  }
  std::string strProxyHost;
  std::string strUsername;
  std::string strPassword;
  std::string strDomain;
  ProxyType nProxyType;
  uint16_t nProxyPort;
  bool bUse;
};

struct ProxyRemoteInfo {
  ProxyRemoteInfo() { Init(); }
  ProxyRemoteInfo& operator=(const ProxyRemoteInfo& info) {
    strRemoteAddr = info.strRemoteAddr;
    uRemoteProxyPort = info.uRemoteProxyPort;

    return *this;
  }
  void Init() { uRemoteProxyPort = 0; }
  std::string strRemoteAddr;
  uint16_t uRemoteProxyPort;
};

#endif  // _SOCKET_PROXY_COMMON_H_
